package com.anjubao.parking.municipal.parkinglot.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrentRecordsResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrentSlotsFreeResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrentSlotsUsedResDto;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingTrentTradesResDto;
import com.anjubao.parking.municipal.parkinglot.service.ParkingStatRecordService;
import com.anjubao.parking.municipal.parkinglot.service.ParkingStatSlotService;
import com.anjubao.parking.municipal.parkinglot.service.ParkingStatTradesService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 停车场趋势业务controller
 * @author zhangyunbo
 */
@RestController
@RequestMapping
@Api(value = "ParkingTrendController",tags ={ "停车场趋势业务API"})
public class ParkingTrendController {

	@Autowired
	private ParkingStatRecordService parkingStatRecordService;
	@Autowired
	private ParkingStatTradesService parkingStatTradesService;
	@Autowired
	private ParkingStatSlotService parkingStatSlotService;


	private static final Logger logger = LoggerFactory.getLogger(ParkingTrendController.class);


	@GetMapping("/parking-trend-records")
	@ApiOperation(value = "2.3.1 分时统计停车记录趋势")
	@ApiImplicitParams({
			@ApiImplicitParam(name="cityId",value="城市id",required = true,dataType = "int",paramType = "query"),
			@ApiImplicitParam(name="type",value = "停车场类型 null:聚合,0:拆分,1:封闭式,2:路内",required = false,dataType = "int",paramType = "query")
	})
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
	/**
	 * 查询
	 *
	 * @param cityId
	 * @param type
	 * @return
	 */
	public ApiResult<List<ParkingTrentRecordsResDto>> getParkingTrendRecords(@RequestParam Integer cityId, Integer type) {
		logger.info("get parking trend records by cityId {} type {}", cityId,type);
		List<ParkingTrentRecordsResDto> resDtos=parkingStatRecordService.getParkingTrendRecords(cityId,type);
		return ApiResult.success(resDtos);
	}


	@GetMapping("/parking-trend-trades")
	@ApiOperation(value = "2.3.2 分时统计停车费用趋势")
	@ApiImplicitParams({
			@ApiImplicitParam(name="cityId",value="城市id",required = true,dataType = "Int",paramType = "query"),
			@ApiImplicitParam(name="type",value = "停车场类型 null:聚合,0:拆分,1:封闭式,2:路内",required = false,dataType = "Int",paramType = "query")
	})
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
	/**
	 * 查询
	 *
	 * @param cityId
	 * @param type
	 * @return
	 */
	public ApiResult<List<ParkingTrentTradesResDto>> getParkingTrendTrades(@RequestParam Integer cityId, Integer type) {
		logger.info("get parking trend trades by cityId {} type {}", cityId,type);
		List<ParkingTrentTradesResDto> resDtos=parkingStatTradesService.getParkingTrendTeades(cityId,type);
		return ApiResult.success(resDtos);
	}

	@GetMapping("/parking-trend-slots/used")
	@ApiOperation(value = "2.3.3 分时统计停车场已用车位趋势")
	@ApiImplicitParams({
			@ApiImplicitParam(name="cityId",value = "城市id",required = true,dataType = "Int",paramType = "query"),
			@ApiImplicitParam(name="type",value = "停车场类型 null:聚合,0:拆分,1:封闭式,2:路内",required = false,dataType = "Int",paramType = "query")
	})
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
	/**
	 * 查询
	 *
	 * @param cityId
	 * @param type
	 * @return
	 */
	public ApiResult<List<ParkingTrentSlotsUsedResDto>> getParkingTrendSlotsUsed(@RequestParam Integer cityId, Integer type) {
		logger.info("get parking trend slots used by cityId {} type {}", cityId,type);
		List<ParkingTrentSlotsUsedResDto> resDtos=parkingStatSlotService.getParkingTrendSlotsUsed(cityId,type);
		return ApiResult.success(resDtos);
	}


	@GetMapping("/parking-trend-slots/free")
	@ApiOperation(value = "2.3.4 分时统计停车场未用车位趋势")
	@ApiImplicitParams({
			@ApiImplicitParam(name="parkingLotCode",value = "停车场code",required = true,dataType = "String",paramType = "query"),
	})
    @ApiResponses(value = {
            @ApiResponse(code = 5000,message = "操作失败")
    })
	/**
	 * 查询
	 *
	 * @param parkingLotCode    停车场code
	 * @return
	 */
	public ApiResult<List<ParkingTrentSlotsFreeResDto>> getParkingTrendSlotsfree(@RequestParam String parkingLotCode) {
		logger.info("get parking trend slots free by parkingLotCode {} ", parkingLotCode);
		List<ParkingTrentSlotsFreeResDto> resDtos=parkingStatSlotService.getParkingTrendSlotsfree(parkingLotCode);
		return ApiResult.success(resDtos);
	}
}